//
//  PedometerTest.swift
//  HSMainViewControllerHandler
//
//  Created by haisheng huang on 2016/9/28.
//  Copyright © 2016年 haisheng huang. All rights reserved.
//

import Foundation
import UIKit


@objc open class PedometerTest: NSObject {
    
    
    class func test() -> Void {
    
        if #available(iOS  8.0, *) {
            
        } else {
            
            var stepCounter: CMStepCounterHandle? = nil
            
            stepCounter = CMStepCounterHandle()
            
            let dateFormatter: DateFormatter = DateFormatter()
            dateFormatter.timeZone = TimeZone.current
            dateFormatter.dateFormat = "yyyy-MM-dd"
//                    let offsetTime: NSInteger = NSTimeZone.systemTimeZone().secondsFromGMT
            //.dateByAddingTimeInterval(Double(offsetTime))
            
            let yesterday:Date = Date.init(timeInterval: -24 * 60 * 60 * 2.0, since: Date())
            let yesterdayStr: String = dateFormatter.string(from: yesterday)
//                    print(yesterdayStr + " 00:00:00")
            dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            
            let startDate: Date = dateFormatter.date(from: yesterdayStr + " 00:00:01")!
            let endDate: Date = dateFormatter.date(from: yesterdayStr + " 23:59:59")!
            
//                    print("startDate: \(startDate), endDate: \(endDate))")
            stepCounter?.queryStepCounts(startDate, endDate: endDate, handler: { (numberOfSteps, error) in
//                            print("numberOfSteps:\(numberOfSteps), error:\(error)")
            })
            
        }
    
    }
    

}

